import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/assets/style/index.less'
import '@/config'
import {getLocalStorageItem, removeLocalStorageItem, setLocalStorageItem} from '@/utils/storage-helper'

Vue.config.productionTip = false

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
//路由守卫
router.beforeEach(function (to, from, next) {

    if (to.meta.needLogin) {
        //页面是否登录
        if (getLocalStorageItem('USER_TOKEN')) {
            //本地存储中是否有token(uid)数据
            next(); //表示已经登录
        } else {
            //next可以传递一个路由对象作为参数 表示需要跳转到的页面
            next({name: 'login'});
        }
    } else {
        //表示不需要登录
        next(); //继续往后走
    }
});
//当前默认页面的权限判断
router.afterEach((to, from) => {
    if (to.path == '/workbench') {
        if (getLocalStorageItem('useToken')) {

        } else {
            removeLocalStorageItem('BreadCrumb')
            router.push('/*/login')
        }
    }
    else {
    }
})
